const sysinfo = wx.getSystemInfoSync()
const app = getApp();
var api = require('../../utils/api.js');
Page({
  data: {},
  //用户点击右上角分享朋友圈
  onShareTimeline: function () {
  },
  //用户点击右上角分享朋友|朋友圈
  onShareAppMessage: function () {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    return {
      title: '秃头鸭',
      path: '/pages/bald/bald'
    }
  },
  //请求方法
  uploads: function () {
    var that = this
    var takephonewidth
    var takephoneheight
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        wx.getImageInfo({
          src: res.tempFilePaths[0],
          success(res) {
            takephonewidth = res.width,
              takephoneheight = res.height
          }
        })
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        if (res.tempFiles[0].size > (4096 * 1024)) {
          wx.showToast({
            title: '图片文件过大哦',
            icon: 'none',
            mask: true,
            duration: 1500
          })
        } else {
          wx.showLoading({
            title: "秃头中...",
            mask: true
          }),
            api.baldRequest(res.tempFilePaths[0], {
            success(result) {
              var resultJ = JSON.parse(result)
              wx.hideLoading();
              if (resultJ.code == 200) {
                wx.navigateTo({
                  url: '/pages/poster/poster?data0=' + encodeURIComponent(resultJ.data.data_0)+'&data1='+encodeURIComponent(resultJ.data.data_1)+'&data2='+ encodeURIComponent(resultJ.data.data_2)+'&jobNum='+resultJ.data.jobNum,
                })
                that.setData({
                  img: 'data:image/jpg;base64,' + resultJ.data.image
                })
              } else {
                if (resultJ.code == 87014) {
                  wx.hideLoading();
                  wx.showModal({
                    content: '存在敏感内容，请更换图片',
                    showCancel: false,
                    confirmText: '明白了'
                  })
                  that.setData({
                    img: null
                  })
                } else {
                  wx.hideLoading();
                  wx.showModal({
                    content: resultJ.msg_zh,
                    showCancel: false,
                    confirmText: '明白了'
                  })
                }
              }
            }
          })
        }
      },
    })
  },
  onLoad: function () {
  },
})
